package work.sajor.wechatpush.controller;

/**
 * @ClassName PushController
 * @Description TODO
 * @Author ydzhao
 * @Date 2022/8/2 15:48
 */

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import work.sajor.wechatpush.service.Pusher;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.logging.SimpleFormatter;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@RestController
public class PushController {
    /**
     * 要推送的用户openid
     */
    @Value("${target.openId}")
    private String target;
    @Value("${target.test.openId}")
    private String testTarget;

    @Autowired
    Pusher pusherService;

    /**
     * 微信测试账号推送
     */
    @GetMapping("/push")
    public void push() {
        pusherService.push(target);
    }

    /**
     * 微信测试账号推送
     */
    @GetMapping("/push/test")
    public void pushTest() {
        pusherService.push(testTarget);
    }


    /**
     * 微信测试账号推送
     */
    @GetMapping("/push/{id}")
    public void pushId(@PathVariable("id") String id) {
        pusherService.push(id);
    }


    @NacosValue(value = "${target.openId}", autoRefreshed = true)
    private String openId;

    @RequestMapping(value = "/get", method = GET)
    @ResponseBody
    public String get() {
        return openId;
    }

    @RequestMapping(value = "test")
    public Object test() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        return "NOW:"+simpleDateFormat.format(new Date()) ;
    }
}